package main

import (
	"fmt"
	"github.com/astaxie/beego/logs"
	tcpserver "nat/tcp"
	"net"
)

func main() {
	conn, err := net.Dial("tcp", "192.168.50.237:5229")
	if err != nil {
		fmt.Println(err)
		return
	}

	defer conn.Close()

	fmt.Println("Connected to server")
	tmp := make([]byte, 0)
	for {
		response := make([]byte, 1024)
		n, err := conn.Read(response)
		if err != nil {
			logs.Error(err.Error())
			return
		}
		var fullList [][]byte
		fullList, tmp = tcpserver.Unpack(append(tmp, response[:n]...))
		for _, body := range fullList {
			logs.Info("来自服务器的新消息:", string(body))
		}
	}
	fmt.Println("Closing connection")
}
